<template>
  <!-- 传入一个course对象 -->
  <view @click="handleClick" class="course-card" @mouseenter="hover = true" @mouseleave="hover = false"
    :class="{ 'hovered': hover }"
    :style="`grid-row: ${course.rowStart+1} / span ${course.rowSpan};grid-column: ${course.day+1}; background-color: ${course.color};`">
    <!-- `字符串中嵌入 ${变量名} 或 ${表达式}` -->
    <text class="course-name">{{course. name }}</text>
    <text class="teacher">{{ course.teacher }}</text>
    <text class="location">{{ course.location }}</text>

  </view>
</template>

<script setup>
  import {
    ref
  } from 'vue'

  const hover = ref(false)
  const emit = defineEmits(['click'])
  const props = defineProps({
    course: {
      type: Object,
      required: true
    }
  })
  //给父组件提供弹窗函数，用于显示具体的课程内容
  function handleClick() {
    emit('click', props.course)


  }
</script>

<style lang="scss" scoped>
  .course-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    padding: 10rpx;
    margin: 5rpx;
    border-radius: 8rpx;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    font-size: 24rpx;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    line-height: 1.2;
    box-sizing: border-box;
    word-break: break-all;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);

    text {
      display: block;
      width: 100%;
      text-align: left;
    }

    .course-name {
      font-weight: bold;
      font-size: 25rpx;
    }

    .location,
    .teacher {
      font-size: 20rpx;
      opacity: 0.9;
      margin-top: 2rpx;
    }
  }

  .course-card.hovered {
    transform: scale(1.03);
    box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.15);
  }
</style>